package personalfinancemanager;

import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

public class MainWindowFrame extends javax.swing.JFrame {

    JInternalFrame chartAreaInternalFrame = new JInternalFrame();
    JInternalFrame barAreaInternalFrame = new JInternalFrame();
//        chartAreaInternalFrame.setSize(500, 500);

    /**
     * Creates new form MainWindowFrame
     */
    public MainWindowFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        overviewPanel = new personalfinancemanager.OverviewPanel();
        transactionsPanel = new personalfinancemanager.TransactionsPanel();
        calendarTab = new javax.swing.JPanel();
        calendarTabPanel = new personalfinancemanager.CalendarTabPanel();
        debtManagerTabPanel = new javax.swing.JPanel();
        jToolBar3 = new javax.swing.JToolBar();
        addNewDebt = new javax.swing.JButton();
        debtCustomizeButton = new javax.swing.JButton();
        graphsTab = new javax.swing.JPanel();
        jToolBar4 = new javax.swing.JToolBar();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanel6 = new javax.swing.JPanel();
        chartAreaPanel = new javax.swing.JPanel();
        barAreaPanel = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        accountSetupWizardMenuItem = new javax.swing.JMenuItem();
        switchAccountsMenuItem = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenu7 = new javax.swing.JMenu();
        calculatorMenuItem = new javax.swing.JMenuItem();
        jMenu6 = new javax.swing.JMenu();

        jMenu3.setText("File");
        jMenuBar2.add(jMenu3);

        jMenu4.setText("Edit");
        jMenuBar2.add(jMenu4);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Personal Finance Manager");

        jTabbedPane1.addTab("Overview", overviewPanel);
        jTabbedPane1.addTab("Transactions", transactionsPanel);

        org.jdesktop.layout.GroupLayout calendarTabLayout = new org.jdesktop.layout.GroupLayout(calendarTab);
        calendarTab.setLayout(calendarTabLayout);
        calendarTabLayout.setHorizontalGroup(
            calendarTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(calendarTabLayout.createSequentialGroup()
                .add(calendarTabPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(0, 123, Short.MAX_VALUE))
        );
        calendarTabLayout.setVerticalGroup(
            calendarTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, calendarTabLayout.createSequentialGroup()
                .add(0, 0, Short.MAX_VALUE)
                .add(calendarTabPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        jTabbedPane1.addTab("Calendar", calendarTab);

        jToolBar3.setRollover(true);

        addNewDebt.setText("Add New Debt");
        addNewDebt.setFocusable(false);
        addNewDebt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addNewDebt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addNewDebt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addNewDebtActionPerformed(evt);
            }
        });
        jToolBar3.add(addNewDebt);

        debtCustomizeButton.setText("Customize");
        debtCustomizeButton.setFocusable(false);
        debtCustomizeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        debtCustomizeButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(debtCustomizeButton);

        org.jdesktop.layout.GroupLayout debtManagerTabPanelLayout = new org.jdesktop.layout.GroupLayout(debtManagerTabPanel);
        debtManagerTabPanel.setLayout(debtManagerTabPanelLayout);
        debtManagerTabPanelLayout.setHorizontalGroup(
            debtManagerTabPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(debtManagerTabPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jToolBar3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 865, Short.MAX_VALUE)
                .addContainerGap())
        );
        debtManagerTabPanelLayout.setVerticalGroup(
            debtManagerTabPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(debtManagerTabPanelLayout.createSequentialGroup()
                .add(jToolBar3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(0, 582, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Debt Manager", debtManagerTabPanel);

        jToolBar4.setRollover(true);

        jButton12.setText("Pie Chart");
        jButton12.setFocusable(false);
        jButton12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jToolBar4.add(jButton12);

        jButton13.setText("Bar Graph");
        jButton13.setFocusable(false);
        jButton13.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton13.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });
        jToolBar4.add(jButton13);

        jScrollPane3.setPreferredSize(new java.awt.Dimension(550, 1100));

        jPanel6.setPreferredSize(new java.awt.Dimension(546, 950));

        chartAreaPanel.setPreferredSize(new java.awt.Dimension(693, 453));

        org.jdesktop.layout.GroupLayout chartAreaPanelLayout = new org.jdesktop.layout.GroupLayout(chartAreaPanel);
        chartAreaPanel.setLayout(chartAreaPanelLayout);
        chartAreaPanelLayout.setHorizontalGroup(
            chartAreaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 826, Short.MAX_VALUE)
        );
        chartAreaPanelLayout.setVerticalGroup(
            chartAreaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 453, Short.MAX_VALUE)
        );

        barAreaPanel.setPreferredSize(new java.awt.Dimension(693, 493));

        org.jdesktop.layout.GroupLayout barAreaPanelLayout = new org.jdesktop.layout.GroupLayout(barAreaPanel);
        barAreaPanel.setLayout(barAreaPanelLayout);
        barAreaPanelLayout.setHorizontalGroup(
            barAreaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 0, Short.MAX_VALUE)
        );
        barAreaPanelLayout.setVerticalGroup(
            barAreaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 464, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(chartAreaPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 826, Short.MAX_VALUE)
                    .add(barAreaPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 826, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .add(chartAreaPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(barAreaPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane3.setViewportView(jPanel6);

        org.jdesktop.layout.GroupLayout graphsTabLayout = new org.jdesktop.layout.GroupLayout(graphsTab);
        graphsTab.setLayout(graphsTabLayout);
        graphsTabLayout.setHorizontalGroup(
            graphsTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(graphsTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(graphsTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 865, Short.MAX_VALUE)
                    .add(graphsTabLayout.createSequentialGroup()
                        .add(jToolBar4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 242, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        graphsTabLayout.setVerticalGroup(
            graphsTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(graphsTabLayout.createSequentialGroup()
                .add(jToolBar4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(24, 24, 24)
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 550, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Graphs", graphsTab);

        jMenu1.setText("File");

        accountSetupWizardMenuItem.setText("Account Setup Wizard");
        accountSetupWizardMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                accountSetupWizardMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(accountSetupWizardMenuItem);

        switchAccountsMenuItem.setText("Switch Accounts");
        jMenu1.add(switchAccountsMenuItem);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        jMenu5.setText("Options");
        jMenuBar1.add(jMenu5);

        jMenu7.setText(" Tools");

        calculatorMenuItem.setText("Calculator");
        jMenu7.add(calculatorMenuItem);

        jMenuBar1.add(jMenu7);

        jMenu6.setText("Help");
        jMenuBar1.add(jMenu6);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 645, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(0, 9, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed

        // Pie Chart
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        //debtManagerTabPanel chart
        pieDataset.setValue("Gas", new Integer(200));
        pieDataset.setValue("Entertainment", new Integer(150));
        pieDataset.setValue("Food", new Integer(300));
        pieDataset.setValue("Auto", new Integer(500));
        pieDataset.setValue("Insurance", new Integer(500));
        pieDataset.setValue("Miscellaneous", new Integer(200));
        pieDataset.setValue("Clothing", new Integer(350));
        JFreeChart chart = ChartFactory.createPieChart3D("Pie Chart", pieDataset, true, true, true);
        PiePlot P = (PiePlot) chart.getPlot();
        //P.setForegroundAlpha(TOP_ALIGNMENT);
//        ChartFrame frame = new ChartFrame("Pie Chart", chart);
        //Instead of using ChartFrame, we can use a ChartPanel.
        ChartPanel pieChartPanel = new ChartPanel(chart);
//        JInternalFrame chartAreaInternalFrame = new JInternalFrame();

        chartAreaInternalFrame.setSize(600, 450); //Set the internal frame size.
        chartAreaInternalFrame.setClosable(true); //Set closable to true so it will have an 'x' to close it
        chartAreaPanel.add(chartAreaInternalFrame); //Add the internal frame to the chart area panel.
        chartAreaInternalFrame.add(pieChartPanel); //Add the pie chart to the internal frame.
        pieChartPanel.setSize(450, 450); //Set the size of the pie chart.

        if (!chartAreaInternalFrame.isVisible()) { //The frame is not visible by default, and if it's not visible, make it visible.
            chartAreaInternalFrame.setVisible(true);
        }
//        frame.setVisible(true);
//        frame.setSize(550,600);


    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        // Bar Graph

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        //Amount
        //Y-axis Variable
        //X-axis Variable
        dataset.setValue(200, "Category", "Gas");
        dataset.setValue(150, "Category", "Entertainment");
        dataset.setValue(300, "Category", "Food");
        dataset.setValue(500, "Category", "Auto");
        dataset.setValue(500, "Category", "Insurance");
        dataset.setValue(350, "Category", "Clothing");
        dataset.setValue(200, "Category", "Miscellaneous");
        //Title of Graph
        //X-axis Title
        //Y-axis Title
        //Dataset Variable
        //Orientation
        JFreeChart chart = ChartFactory.createBarChart("Category vs. Amount", "Category", "Amount $", dataset, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black); //declare variable p

        ChartPanel barChartPanel = new ChartPanel(chart);
//        JInternalFrame chartAreaInternalFrame = new JInternalFrame();

        barAreaInternalFrame.setSize(600, 450); //Set the internal frame size.
        barAreaInternalFrame.setClosable(true); //Set closable to true so it will have an 'x' to close it.
        barAreaPanel.add(barAreaInternalFrame); //Add the internal frame to the bar area panel.
        barAreaInternalFrame.add(barChartPanel); //Add the bar chart to the internal frame.
        barChartPanel.setSize(450, 450); //Set the size of the bar chart.

        if (!barAreaInternalFrame.isVisible()) { //The frame is not visible by default, and if it's not visible, make it visible.
            barAreaInternalFrame.setVisible(true);
        }

        /* ChartFrame frame = new ChartFrame("Bar Chart", chart);//declare frame
         frame.setVisible(true);
         frame.setSize(600, 500);//assign frame size*/

    }//GEN-LAST:event_jButton13ActionPerformed

    private void accountSetupWizardMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_accountSetupWizardMenuItemActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_accountSetupWizardMenuItemActionPerformed

    private void addNewDebtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewDebtActionPerformed
        // TODO add your handling code here:
        System.out.println("New debt button added");
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() { // open the window to add a new debt
                new DebtAddingWindow().setVisible(true);
            }
        });

    }//GEN-LAST:event_addNewDebtActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainWindowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainWindowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainWindowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainWindowFrame().setVisible(true);
            }
        });
    }

    //Provides way to return the panel to the main class, PersonalFinanceManager.
    public OverviewPanel getOverviewPanel() {
        return overviewPanel;
    }

    /**
     * Provides way to return the transactions table to the main class,
     * PersonalFinanceManager.
     *
     * @return The transactions table from the transactions tab.
     */
//    public JTable getTransactionsTable() {
//        return transactionsTable;
//    }
    public TransactionsPanel getTransactionsPanel() {
        return transactionsPanel;
    }
    
    /**
     * Provides way to return the calendar tab panel to the main class,
     * PersonalFinanceManager.
     * @return The calendar panel from the calendar tab.
     */
    public CalendarTabPanel getCalendarTabPanel() {
        return calendarTabPanel;
    }

    /**
     * Provides way to return the debt manager tab panel to the main class,
     * PersonalFinanceManager.
     *
     * @return The debt manager panel from the debts tab.
     */
    public JPanel getDebtManagerTabPanel() {
        return debtManagerTabPanel;
    }

    /**
     * Public method to add account setup wizard menu item action listener, which can be called
     * from PersonalFinanceManager.java (the main class).
     * @param al 
     */
    public void addAccountSetupWizardMenuItemActionListener(ActionListener al) {
        accountSetupWizardMenuItem.addActionListener(al);
    }

    /**
     * Public method to add calculator menu item action listener, which can be called
     * from PersonalFinanceManager.java (the main class).
     * @param al 
     */
    public void addCalculatorMenuItemActionListener(ActionListener al) {
        calculatorMenuItem.addActionListener(al);
    }

    public void addSwitchAccountsMenuItemActionListener(ActionListener al) {
        switchAccountsMenuItem.addActionListener(al);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem accountSetupWizardMenuItem;
    private javax.swing.JButton addNewDebt;
    private javax.swing.JPanel barAreaPanel;
    private javax.swing.JMenuItem calculatorMenuItem;
    private javax.swing.JPanel calendarTab;
    private personalfinancemanager.CalendarTabPanel calendarTabPanel;
    private javax.swing.JPanel chartAreaPanel;
    private javax.swing.JButton debtCustomizeButton;
    private javax.swing.JPanel debtManagerTabPanel;
    private javax.swing.JPanel graphsTab;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenu jMenu7;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JToolBar jToolBar4;
    private personalfinancemanager.OverviewPanel overviewPanel;
    private javax.swing.JMenuItem switchAccountsMenuItem;
    private personalfinancemanager.TransactionsPanel transactionsPanel;
    // End of variables declaration//GEN-END:variables
}
